import { styled, useSearchParams } from '@umijs/max'
import { useEffect, useState } from 'react'

const Container = styled.div`
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
  height: 100%;
`

const Agreement: React.FC = () => {
  const [urlParams] = useSearchParams()
  const [type, setType] = useState<string>()
  const [wordUrls] = useState<Record<string, string>>({
    user: 'https://homechargesmall.liaoqianapp.com/img/user.pdf',
    privacy: 'https://homechargesmall.liaoqianapp.com/img/privacy.pdf',
  })

  useEffect(() => {
    const type = urlParams.get('type')
    setType(type || 'user')
  }, [])

  return (
    <Container>
      {type ? <embed src={wordUrls[type]} type="application/pdf" width="100%" height="100%" /> : null}
    </Container>
  )
}

export default Agreement
